// 迭代器模式

const todos = {
    life: ["吃饭", "睡觉", "打游戏"],
    learn: ["语文", "历史", "数学"],
    work: ["喝茶"],
    each(callback) {
        const all = [...this.life, ...this.learn, ...this.work]
        for (const iterator of all) {
            callback(iterator)
        }
    },
    [Symbol.iterator] :function () {
        const all = [...this.life, ...this.learn, ...this.work]
        let index = 0;
        return {
            next() {
                return {
                    value: all[index],
                    done: index++ >= all.length
                }
            }
        }
    }
}

for (const iterator of todos) {
    console.log("iterator", iterator)
}